/*
 * strncpy_s.c - Safe bounded string copy with bounds checking
 */

#include "bounds_check.h"
#include "bounds_check_internal.h"
#include <string.h>

int strncpy_s(char *dest, size_t dest_size, const char *src, size_t count) {
    if (!is_valid_buffer(dest, dest_size) || src == NULL) {
        return BOUNDS_CHECK_INVALID_PARAM;
    }

    if (count >= dest_size) {
        /* Not enough space for null terminator */
        dest[0] = '\0';
        return BOUNDS_CHECK_BUFFER_TOO_SMALL;
    }

    size_t i;
    for (i = 0; i < count && src[i] != '\0'; i++) {
        dest[i] = src[i];
    }

    /* Always null terminate */
    dest[i] = '\0';

    return BOUNDS_CHECK_SUCCESS;
}